package com.test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by frinder on 2017/5/17.
 */
public class StreamDemo {


    static List<Stu> stuList = new ArrayList() {{
        add(new Stu("name1", 15));
        add(new Stu("name2", 16));
        add(new Stu("name3", 17));
    }};


    public static void main(String[] args) {
        // map();
        peek();
    }


    public static void map() {
        stuList.parallelStream().map(s -> {
            s.setName(s.getName() + ":" + s.getAge());
            return s;
        })
                //.count();
                .collect(Collectors.toList());
        System.out.println(stuList);
    }

    public static void peek() {
        stuList.parallelStream().peek(s -> s.setName(s.getName() + ":" + s.getAge()))
                // .count();
                .collect(Collectors.toList());
        System.out.println(stuList);
    }


    public static class Stu {
        private String name;

        private int age;

        public Stu() {
        }

        public Stu(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "Stu{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }


    }

}
